Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the Topics class.
	''' </summary>
	<Serializable> _
	Public Partial Class TopicsCollection 
	Inherits ActiveList(Of Topics, TopicsCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the Topics table.
	''' </summary>
	<Serializable> _
	Public Partial Class Topics 
	Inherits ActiveRecord(Of Topics)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("Topics", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarTopicid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarTopicid.ColumnName = "topicid"
                colvarTopicid.DataType = DbType.Int32
                colvarTopicid.MaxLength = 0
                colvarTopicid.AutoIncrement = true
                colvarTopicid.IsNullable = false
                colvarTopicid.IsPrimaryKey = true
                colvarTopicid.IsForeignKey = false
                colvarTopicid.IsReadOnly = false
                
                
                schema.Columns.Add(colvarTopicid)
                
                Dim colvarTopic As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarTopic.ColumnName = "topic"
                colvarTopic.DataType = DbType.String
                colvarTopic.MaxLength = 255
                colvarTopic.AutoIncrement = false
                colvarTopic.IsNullable = false
                colvarTopic.IsPrimaryKey = false
                colvarTopic.IsForeignKey = false
                colvarTopic.IsReadOnly = false
                
						colvarTopic.DefaultSetting = "('No Topic')"
				
                
                schema.Columns.Add(colvarTopic)
                
                Dim colvarDescription As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarDescription.ColumnName = "description"
                colvarDescription.DataType = DbType.String
                colvarDescription.MaxLength = 255
                colvarDescription.AutoIncrement = false
                colvarDescription.IsNullable = true
                colvarDescription.IsPrimaryKey = false
                colvarDescription.IsForeignKey = false
                colvarDescription.IsReadOnly = false
                
                
                schema.Columns.Add(colvarDescription)
                
                Dim colvarSection As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarSection.ColumnName = "section"
                colvarSection.DataType = DbType.Boolean
                colvarSection.MaxLength = 0
                colvarSection.AutoIncrement = false
                colvarSection.IsNullable = false
                colvarSection.IsPrimaryKey = false
                colvarSection.IsForeignKey = false
                colvarSection.IsReadOnly = false
                
						colvarSection.DefaultSetting = "((0))"
				
                
                schema.Columns.Add(colvarSection)
                
                Dim colvarWeight As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarWeight.ColumnName = "weight"
                colvarWeight.DataType = DbType.Int32
                colvarWeight.MaxLength = 0
                colvarWeight.AutoIncrement = false
                colvarWeight.IsNullable = false
                colvarWeight.IsPrimaryKey = false
                colvarWeight.IsForeignKey = false
                colvarWeight.IsReadOnly = false
                
						colvarWeight.DefaultSetting = "((1))"
				
                
                schema.Columns.Add(colvarWeight)
                
                Dim colvarLocked As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarLocked.ColumnName = "locked"
                colvarLocked.DataType = DbType.Boolean
                colvarLocked.MaxLength = 0
                colvarLocked.AutoIncrement = false
                colvarLocked.IsNullable = false
                colvarLocked.IsPrimaryKey = false
                colvarLocked.IsForeignKey = false
                colvarLocked.IsReadOnly = false
                
						colvarLocked.DefaultSetting = "((0))"
				
                
                schema.Columns.Add(colvarLocked)
                
                Dim colvarVisible As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarVisible.ColumnName = "visible"
                colvarVisible.DataType = DbType.Boolean
                colvarVisible.MaxLength = 0
                colvarVisible.AutoIncrement = false
                colvarVisible.IsNullable = false
                colvarVisible.IsPrimaryKey = false
                colvarVisible.IsForeignKey = false
                colvarVisible.IsReadOnly = false
                
						colvarVisible.DefaultSetting = "((0))"
				
                
                schema.Columns.Add(colvarVisible)
                
                Dim colvarModeratorkey As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarModeratorkey.ColumnName = "moderatorkey"
                colvarModeratorkey.DataType = DbType.Guid
                colvarModeratorkey.MaxLength = 0
                colvarModeratorkey.AutoIncrement = false
                colvarModeratorkey.IsNullable = true
                colvarModeratorkey.IsPrimaryKey = false
                colvarModeratorkey.IsForeignKey = false
                colvarModeratorkey.IsReadOnly = false
                
                
                schema.Columns.Add(colvarModeratorkey)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("Topics",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("Topicid")> _
        Public Property Topicid As Integer 
			Get
				Return GetColumnValue(Of Integer)("topicid")
			End Get
		    
			Set
				SetColumnValue("topicid", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Topic")> _
        Public Property Topic As String 
			Get
				Return GetColumnValue(Of String)("topic")
			End Get
		    
			Set
				SetColumnValue("topic", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Description")> _
        Public Property Description As String 
			Get
				Return GetColumnValue(Of String)("description")
			End Get
		    
			Set
				SetColumnValue("description", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Section")> _
        Public Property Section As Boolean 
			Get
				Return GetColumnValue(Of Boolean)("section")
			End Get
		    
			Set
				SetColumnValue("section", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Weight")> _
        Public Property Weight As Integer 
			Get
				Return GetColumnValue(Of Integer)("weight")
			End Get
		    
			Set
				SetColumnValue("weight", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Locked")> _
        Public Property Locked As Boolean 
			Get
				Return GetColumnValue(Of Boolean)("locked")
			End Get
		    
			Set
				SetColumnValue("locked", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Visible")> _
        Public Property Visible As Boolean 
			Get
				Return GetColumnValue(Of Boolean)("visible")
			End Get
		    
			Set
				SetColumnValue("visible", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Moderatorkey")> _
        Public Property Moderatorkey As Nullable(Of Guid) 
			Get
				Return GetColumnValue(Of Nullable(Of Guid))("moderatorkey")
			End Get
		    
			Set
				SetColumnValue("moderatorkey", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
	    #Region "PrimaryKey Methods"
	    
			Public Function ThreadsRecords() As Data.ThreadsCollection 
	
				Return New Data.ThreadsCollection().Where(Threads.Columns.Topicid, Topicid).Load()
	
			End Function
			
		#End Region
		
		
		
		
		
		
	    
	    'no foreign key tables defined (0)
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varTopic As String,ByVal varDescription As String,ByVal varSection As Boolean,ByVal varWeight As Integer,ByVal varLocked As Boolean,ByVal varVisible As Boolean,ByVal varModeratorkey As Nullable(Of Guid))
			Dim item As Topics = New Topics()
			
            item.Topic = varTopic
            
            item.Description = varDescription
            
            item.Section = varSection
            
            item.Weight = varWeight
            
            item.Locked = varLocked
            
            item.Visible = varVisible
            
            item.Moderatorkey = varModeratorkey
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varTopicid As Integer,ByVal varTopic As String,ByVal varDescription As String,ByVal varSection As Boolean,ByVal varWeight As Integer,ByVal varLocked As Boolean,ByVal varVisible As Boolean,ByVal varModeratorkey As Nullable(Of Guid))
			Dim item As Topics = New Topics()
		    
                item.Topicid = varTopicid
				
                item.Topic = varTopic
				
                item.Description = varDescription
				
                item.Section = varSection
				
                item.Weight = varWeight
				
                item.Locked = varLocked
				
                item.Visible = varVisible
				
                item.Moderatorkey = varModeratorkey
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared Topicid As String = "topicid"
            
            Public Shared Topic As String = "topic"
            
            Public Shared Description As String = "description"
            
            Public Shared Section As String = "section"
            
            Public Shared Weight As String = "weight"
            
            Public Shared Locked As String = "locked"
            
            Public Shared Visible As String = "visible"
            
            Public Shared Moderatorkey As String = "moderatorkey"
            
		End Structure
		#End Region
	End Class
End Namespace
